package com.wwdablu.soumya.lottiebottomnav;

import com.wwdablu.soumya.lottiebottomnav.util.Util;

/**
 * MenuItemBuilder
 *
 * @since 2021-05-19
 */
public class MenuItemBuilder {
    private MenuItem menuItem;

    private MenuItemBuilder(String lottieName,
                            FontItem fontItem,
                            Object tag) {
        menuItem = new MenuItem();
        menuItem.fontItem = fontItem;
        menuItem.selectedLottieName = lottieName;
        menuItem.unselectedLottieName = lottieName;
        menuItem.tag = tag;
    }

    /**
     * create
     *
     * @param lottieName
     * @param fontItem
     * @param tag
     * @return MenuItemBuilder
     * @throws IllegalArgumentException
     */
    public static MenuItemBuilder create(String lottieName,
                                         FontItem fontItem,
                                         Object tag) throws IllegalArgumentException {
        if (Util.isEmpty(lottieName)) {
            throw new IllegalArgumentException("Lottie file must be provided.");
        }

        return new MenuItemBuilder(lottieName,
                fontItem, tag);
    }

    /**
     * createFrom
     *
     * @param menuItem
     * @return MenuItemBuilder
     */
    public static MenuItemBuilder createFrom(MenuItem menuItem) {
        return createFrom(menuItem, FontBuilder.create(menuItem.fontItem).build());
    }

    /**
     * createFrom
     *
     * @param menuItem
     * @param fontItem
     * @return MenuItemBuilder
     */
    public static MenuItemBuilder createFrom(MenuItem menuItem, FontItem fontItem) {
        MenuItemBuilder builder = create(
                menuItem.selectedLottieName,
                fontItem,
                null);

        builder.menuItem.selectedLottieName = menuItem.selectedLottieName;
        builder.menuItem.unselectedLottieName = menuItem.unselectedLottieName;

        builder.menuItem.lottieProgress = menuItem.lottieProgress;

        builder.menuItem.loop = menuItem.loop;
        return builder;
    }

    /**
     * selectedLottieName
     *
     * @param lottieName
     * @return MenuItemBuilder
     */
    public MenuItemBuilder selectedLottieName(String lottieName) {
        menuItem.selectedLottieName = lottieName;
        return this;
    }

    /**
     * unSelectedLottieName
     *
     * @param lottieName
     * @return MenuItemBuilder
     */
    public MenuItemBuilder unSelectedLottieName(String lottieName) {
        menuItem.unselectedLottieName = lottieName;
        return this;
    }

    /**
     * pausedProgress
     *
     * @param progress
     * @return MenuItemBuilder
     */
    public MenuItemBuilder pausedProgress(float progress) {
        if (progress <= 0) progress = 0;
        else if (progress >= 1) progress = 1;
        menuItem.lottieProgress = progress;
        return this;
    }

    /**
     * loop
     *
     * @param loop
     * @return MenuItemBuilder
     */
    public MenuItemBuilder loop(boolean loop) {
        menuItem.loop = loop;
        return this;
    }

    /**
     * tag
     *
     * @param tag
     * @return MenuItemBuilder
     */
    public MenuItemBuilder tag(Object tag) {
        menuItem.tag = tag;
        return this;
    }

    /**
     * build
     *
     * @return MenuItem
     */
    public MenuItem build() {
        return menuItem;
    }
}

